import { API_CONFIG } from "../config/index.js";
import request from '../api/index.js'
const BASE_URL = import.meta.env.VITE_BASE_URL

// 定义deployment|statefulset|daemonset|cronjob 控制器通用的删除方法
export const deleteHandler = (clusterId, namespace, name, resourceType) => {
    const resourceTypeTemp = resourceType.toLowerCase()
    const url = `${BASE_URL}/${resourceTypeTemp}/delete`
    return request(url, {clusterId, namespace, name}, "post", 2000)
}

// 定义deployment|statefulset|daemonset|cronjob 控制器通用更新的方法
export const updateHandler = (clusterId, namespace, name, resourceType, item) => {
    const resourceTypeTemp = resourceType.toLowerCase()
    const url = `${BASE_URL}/${resourceTypeTemp}/update`
    return request(url, {clusterId, namespace, name, item}, "post", 2000)
}

// 定义deployment|statefulset|daemonset|cronjob 控制器通用查询列表方法
export const listHandler = (clusterId, namespace, resourceType) => {
    const resourceTypeTemp = resourceType.toLowerCase()
    const url = `${BASE_URL}/${resourceTypeTemp}/list`
    return request(url, {clusterId, namespace}, "get", 2000)
}

// 定义deployment|statefulset|daemonset 控制器通用重启方法
export const restartHandler = (clusterId, namespace, resourceType, name) => {
    const resourceTypeTemp = resourceType.toLowerCase()
    const url = `${BASE_URL}/${resourceTypeTemp}/restart`
    return request(url, {clusterId, namespace, name}, "get", 2000)
}
